package com.awangyh.jdk8.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Created by admin on 2017/4/6.
 */
public class DemoTask implements Runnable {

    private CountDownLatch threadSignal;


    public DemoTask(CountDownLatch threadSignal) {
        this.threadSignal = threadSignal;
    }


    @Override
    public void run() {
        try {
            System.out.println(Thread.currentThread().getName() + "开始...");
            System.out.println(Thread.currentThread().getName() + "一共有" + threadSignal.getCount() + "个线程在处理...");
            TimeUnit.SECONDS.sleep(10);
            threadSignal.countDown();
            System.out.println(Thread.currentThread().getName() + "结束. 还有" + threadSignal.getCount() + " 个线程");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
